<?php 
include ("dbclass.php");
class process extends Database {
	
	private $valueA;
	private $valueB;
	private $valueC;
	private $inputunits;
	private $untidata;
	private $depth;
	private $datedata = array();
	private $pza = array();
	private $pab = array();
	private $graph = array();
	private $datapoly;
	private $mH2O;
	private $v;
		
	public function __construct()
	 {
		 parent::__construct();
	 }
	 
	 
	 public function valuepz($pointpz)
	 {
		 $strsql = $this->selectdatasql("*","piezometer A,localtionpz B","A.id_pz = '$pointpz' and A.location = B.id_local");
		 $datapz = $this->mysqlfetcharray($strsql);
		 $this->valueA =  $datapz[a];
		 $this->valueB =  $datapz[b];
		 $this->valueC =  $datapz[c];
		 $this->depth =  $datapz['depth'];
		 $this->v = $datapz['valuepolt'];;
		
		 return $datapz;	
	 }
		 
		 
		public function setdatapz($pointer,$numpz)
		{
			
			$table = "pz0".$pointer."a";
			$table1 = "pz0".$pointer."b";
		
			$sql = $this->selectdatasql("measureddate,$table,$table1","$numpz","");
			$i = 0;
			while($rowdata = $this->mysqlfetcharray($sql))
				{
				$this->datedata[$i] = $rowdata[measureddate];
				$this->pza[$i] = $rowdata[$table];
				$this->pzb[$i] = $rowdata[$table1];
				
				
				$i++;
				}
				
			return mysql_num_rows($sql);
				
			}
			
			public function getdataarray($i)
			{
				
				return $this->pza[$i];
			}	
			
			
			public function getdataarray1($i)
			{
				return $this->pzb[$i];
			}
			
			
			public function getdatedata($i)
			{
				return $this->datedata[$i];
			}
			
			
	 
	 
			 public function units($inputdata)
			 {
				 $this->inputunits = ($inputdata*$inputdata)/1000;
				 $this->untidata = $this->inputunits;
				 return  $this->untidata;
			 }
			
			
			public function getvalueA()
			{
				return $this->valueA;
			}
			
			
		
			public function Polynomial($T)
			{
				$MP = '0.000';
				//$a = '1.41155E-01';
				$data = round($this->untidata,2);
				//echo $T;
				//echo $this->valueC;
				$this->datapoly = ($this->valueA*($data*$data)+($this->valueB*$data)+$this->valueC + $MP*($T - $this->v ))*1000;
				$datapoly1 = ($this->valueA*($data*$data)+($this->valueB*$data)+$this->valueC );
				return $this->datapoly;
			}
			
			public function mH2O()
			{
				$k = 101.97162129779;
				$this->mH2O = (round($this->datapoly,2)* $k)/1000;
				return $this->mH2O;
				
				}
				
				
			public function Diff($datanum)
			{
				return $this->mH2O - $datanum;
				
				}
				
				
				public function Piezo()
				{
				return $this->depth - $this->mH2O;	
				}
				
				
			public function addararygraph($i,$data)
			{
					
					$this->graph[$i] = $data;
				
			}
			
			
			public function getdatagraph($i)
			{
				return 	$this->graph[$i];
			}
				
				
			  
			public function DateThai($strDate)
			{
				$strYear = substr((date("Y",strtotime($strDate))+543),2,5);
				$strMonth= date("n",strtotime($strDate));
				$strDay= date("j",strtotime($strDate));
				$strHour= date("H",strtotime($strDate));
				$strMinute= date("i",strtotime($strDate));
				$strSeconds= date("s",strtotime($strDate));
				$strMonthCut = Array("","ม.ค.","ก.พ.","มี.ค.","เม.ย.","พ.ค.","มิ.ย.","ก.ค.","ส.ค.","ก.ย.","ต.ค.","พ.ย.","ธ.ค.");
				$strMonthThai=$strMonthCut[$strMonth];
				return "$strDay $strMonthThai $strYear" ;
				
			}

	}
?>